package com.situ.day3;

import javafx.scene.control.RadioMenuItem;
import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

public class ContinueBeakDemo {

    //continue：跳出本次循环，继续下一次循环
    //break：跳出离他最近的那层循环
    @Test
    public void test1() {
        for (int i = 1; i <= 10; i++) {
            if (i == 5) {
                continue;
            }
            System.out.println("i: " + i);
        }
    }

    @Test
    public void test2() {
        for (int i = 1; i <= 10; i++) {
            if (i == 5) {
                break;
            }
            System.out.println("i: " + i);
        }
    }

    @Test
    public void test3() {
        for (int i = 1; i <= 10; i++) {
            System.out.println("i: " + i);
            for (int j = 1; j <= 10; j++) {
                if (j == 5) {
                    break;
                }
                System.out.println("j: " + j);
            }
        }
    }

    @Test
    public void test545() {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        //Random生成随机数的一个类，里面有个方法nextInt可以帮我们生成指定范围随机数
        //int value between zero (inclusive) and bound (exclusive)
        // [0,1000) + 1 = [1,1000]
        int rand = random.nextInt(1000) + 1;
        System.out.println(rand);
        while (true) {// for(;;) {}
            System.out.println("猜吧");
            int guess = scanner.nextInt();
            if (guess > rand) {
                System.out.println("太大了");
            } else if (guess < rand) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜你，猜对了");
                break;
            }

            /*
            System.out.println("是否要退出？0：退出，输入任意继续");
            int quit = scanner.nextInt();
            if (quit == 0) {
                break;
            }*/
        }
    }

    // 双重for循环：
//    ****
//    ****
//    ****
    @Test
    public void test78() {
        for (int i = 1; i <= 3; i++) {
            System.out.println("*");
        }
        System.out.println("-------------");
        for (int i = 1; i <= 4; i++) {
            System.out.print("*");
        }
        System.out.println("-------------");
        for (int i = 1; i <= 3; i++) {
            // i=1代表打印第一行
            for (int j = 1; j <= 4; j++) {
                //打印一行的时候不需要换行
                System.out.print("*");
            }
            //打印完一行之后换行
            System.out.println();
        }
    }
    
//    *
//    **
//    ***
//    ****
//    *****
    @Test
    public void test34() {
        for (int i = 1; i <= 5; i++) {
            // i=1  j=1
            // i=2  j=2
            // i=3  j=3
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    @Test
    public void test99 () {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                //System.out.print("2*7=14\t");
                System.out.print(j + "*" + i + "=" + (i * j) + "\t");
            }
            System.out.println();
        }
    }

//         *
//        ***
//       *****
//      *******
//     *********
//    ***********

//    -----*
//    ----***
//    ---*****
//    --*******
//    -*********
//    ***********
    @Test
    public void test45() {
        //i=1   j=1   j=5
        //i=2   j=3   j=4
        //i=3   j=5   j=3
        //i=4   j=7   j=2
        //j=2*i-1
        for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= (6 - i); j++) {
                System.out.print("-");
            }
            for (int j = 1; j <= (2 * i - 1); j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

}
